package sinochem.bpmrefactor.rabbitlistener.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author : jiagang
 * @date : Created in 2021/9/30 10:58
 */
@Component
@RabbitListener(bindings = @QueueBinding(
        exchange = @Exchange("directExchange"), // 交换机(直连)
        key = "testRouting",                // 路由key
        value = @Queue("testQueue"))) //监听队列的名称
public class TestConsumer {

    @RabbitHandler
    public void process(@Payload Map message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) throws Exception{
        System.out.println("testReceiver消费者收到消息  : " + message.toString());
        channel.basicAck(deliveryTag,true);
    }
}
